<template>
  <div class="app-container" ref="appcontainer">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="平台是否回复"  prop="platformContent">
        <el-select v-model="queryParams.platformContent" placeholder="请选择平台回复文字" clearable size="small">
          <el-option
            v-for="dict in platformContentOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="综合星级" prop="platformLevel">
        <el-input
          v-model="queryParams.platformLevel"
          placeholder="请输入综合星级"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary"   size="mini" @click="handleQuery">搜索</el-button>
        <el-button  size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['shopping:comment:remove']"
        >删除</el-button>
      </el-col>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :height="tableHeight" :data="commentList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" show-overflow-tooltip />
<!--      <el-table-column label="主键" align="center" prop="id" />-->
<!--      <el-table-column label="订单id" align="center" prop="orderId" />-->
<!--      <el-table-column label="评价人id" align="center" prop="memberId" />-->
      <el-table-column label="评价人昵称" align="center" prop="memberNickName" />
      <el-table-column label="评价人头像" align="center" prop="memberHeadImg" >
      <template width="120" slot-scope="scope">
        <img style="width:60px;height:60px;border:none;" :src="scope.row.memberHeadImg">
      </template>
      </el-table-column>
<!--      <el-table-column label="商品id" align="center" prop="productId" />-->
      <el-table-column label="商品名称" align="center" prop="productName" />
      <el-table-column label="评价文字" align="center" prop="commentContent" :show-overflow-tooltip="true"/>
      <el-table-column width="200" label="评价图片" align="center" prop="commentImages" >
      <template  slot-scope="scope">
<!--        <ImageScan v-model="scope.row.commentImages"/>-->
        <imageUpload
          v-model="scope.row.commentImages" :hideAdd="true" :isShowTip="false" :disabled="true"/>
      </template>
      </el-table-column>
      <el-table-column label="评价视频" align="center" prop="commentVideo">
<!--      <template width="120" slot-scope="scope">-->
<!--        <img style="width:60px;height:60px;border:none;" :src="scope.row.commentVideo">-->
<!--      </template>-->
        <template slot-scope="scope">
          <div v-if="scope.row.commentVideo">
            <el-button
              type="success"
              plain
              @click="playVideo(scope.row.commentVideo)"
              ref="btn"
              size="mini"
            >播 放</el-button>
          </div>
          <div v-else>暂无视频</div>
        </template>
      </el-table-column>
      <el-table-column label="回复内容" align="center" prop="platformContent" :show-overflow-tooltip="true"/>
<!--      <el-table-column label="平台回复人id" align="center" prop="platformUserId" />-->
      <el-table-column label="平台回复时间" align="center" prop="platformContentTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.platformContentTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="综合星级" align="center" prop="platformLevel" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['shopping:comment:edit']"
          >回复</el-button>
          <el-button
          size="mini"
          type="text"
          @click="handleDelete(scope.row)"
          v-hasPermi="['shopping:comment:remove']"
        >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
    <!-- 视频 -->
    <el-dialog
      title="视频预览"
      :visible.sync="dialogPlay"
      width="30%"
      @close="closeDialog"
    >
      <video
        :src="commentVideo"
        controls
        autoplay
        class="video"
        ref="dialogVideo"
        width="100%"
      ></video>
    </el-dialog>
    <!-- 添加或修改商品评价对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="回复内容" prop="platformContent">
          <el-input v-model="form.platformContent" placeholder="请输入评价文字" />
        </el-form-item>
<!--        <el-form-item label="平台回复时间" prop="platformContentTime">-->
<!--          <el-date-picker clearable size="small"-->
<!--            v-model="form.platformContentTime"-->
<!--            type="date"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            placeholder="选择平台回复时间">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitContent">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listComment, getComment, logicDelComment, addComment, updateComment, exportComment } from "@/api/shopping/comment";

export default {
  name: "Comment",
  data() {
    return {
      // 视频播放
      dialogPlay: false,
      commentVideo:"",
      // 平台回复文字字典
      platformContentOptions: [],
      tableHeight:0,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 商品评价表格数据
      commentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        memberId: null,
        memberNickName: null,
        memberHeadImg: null,
        productId: null,
        productName: null,
        commentContent: null,
        commentImages: null,
        commentVideo: null,
        platformContent: null,
        platformUserId: null,
        platformContentTime: null,
        platformLevel: null,
      },
      // 表单参数
      form: {},
      videoFileType:["mp4"],
      // 表单校验
      rules: {
        platformContent:[
          { required: true, message: "请填写回复内容", trigger: "blur" }
        ],
        memberNickName: [
          { required: true, message: "评价人昵称不能为空", trigger: "blur" }
        ],
        productName: [
          { required: true, message: "商品名称不能为空", trigger: "blur" }
        ],
      }
    };
  },
  beforeRouteEnter(to, form, next) {
    next(vm => {
      const techId = vm.$route.query && vm.$route.query.id;
      vm.queryParams.productId = techId
      vm.getList();
    });
  },
  created() {
    // this.getList();
    this.calHeight()
    this.getDicts("sys_yes_no").then(response => {
      this.platformContentOptions = response.data;
    });
    },
  watch: {
    'showSearch':'calHeight'
  },
  methods: {
    // 视频
    playVideo(url) {
      this.dialogPlay = true;
      this.commentVideo = url;
    },
    closeDialog() {
      this.commentVideo = ""; //清空数据 关闭视频播放
    },
    calHeight () {
          this.$nextTick(() => {
              const rect = this.$refs.appcontainer.getBoundingClientRect();
              let height= this.$refs.queryForm.$el.offsetHeight;
              this.tableHeight = rect.height-height-120;
          })
      },
    /** 查询商品评价列表 */
    getList() {
      this.loading = true;
      listComment(this.queryParams).then(response => {
        this.commentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderId: null,
        memberId: null,
        memberNickName: null,
        memberHeadImg: null,
        productId: null,
        productName: null,
        commentContent: null,
        commentImages: null,
        commentVideo: null,
        platformContent: null,
        platformUserId: null,
        platformContentTime: null,
        platformLevel: null,
        delState: null,
        delUser: null,
        delType: null,
        delTime: null,
        createBy: null,
        createType: null,
        createTime: null,
        updateBy: null,
        updateType: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.showSearch=false;
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商品评价";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getComment(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "评价回复";
      });
    },

    /** 评价提交按钮 */
    submitContent(){
      this.$refs["form"].validate(valid => {
        if (valid) {
          updateComment(this.form).then(response => {
            this.msgSuccess("回复成功");
            this.open = false;
            this.getList();
          });
        }
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateComment(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addComment(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return logicDelComment(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有商品评价数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportComment(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>
<style scoped>
  video{
    height: 100%;
    width: 100%;
    object-fit:scale-down;
  }
  .el-tooltip__popper{
    max-width:20%;
  }
  .el-tooltip__popper,.el-tooltip__popper.is-dark{
    background:rgb(48, 65, 86) !important;
    color: #fff !important;
    line-height: 24px;
  }
  /deep/ .el-upload--picture-card{
    width: 60px;
    height: 60px;
    line-height: 66px;
  }
  /deep/ .el-upload-list--picture-card .el-upload-list__item{
    width: 60px;
    height: 60px;
    margin: 0;
  }
  /deep/ .el-upload-list__item-status-label{
    display: none;
  }

</style>
<style>

</style>
